package org.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.bean.Book;

import java.util.List;
import java.util.Set;

/**
 * @Auther:Liu
 * @Testname:BookMapper
 * @Date:2025/8/6 11:40
 */
@Mapper
public interface BookMapper extends BaseMapper<Book> {

    //查询低价书
    @Select("select * from book b ,discount d where b.is_deleted=0 and b.id=d.book_id order by d.discount_rate limit #{number}")
    List<Book> findLower(int number);

    //排序查询的低价书
    @Select("select * from book b ,discount d where b.is_deleted=0 and b.id=d.book_id order by d.discount_rate limit #{start},10")
    List<Book> findLowerMore(int start);

    //二级搜索低价书（按名称）
    @Select("select * from book b ,discount d where b.is_deleted=0 and b.id=d.book_id and b.name like #{bookname} order by d.discount_rate limit #{start},10")
    List<Book> findLowerAndBooknameMore(@Param("start") int start, @Param("bookname") String bookname);

    //查询低价书的条数
    @Select("select count(0) from book b ,discount d where b.is_deleted=0 and b.id=d.book_id order by d.discount_rate")
    int findLowerMoreCount();

    //查询二级搜索后的低价书的条数
    @Select("select count(0) from book b ,discount d where b.is_deleted=0 and b.id=d.book_id and b.name like #{bookname} order by d.discount_rate")
    int findLowerAndBooknameMoreCount(String bookname);

    List<Book> findBookByBookId(Set<String> set);
}
